function init() {
    $.ajax({
        type: "post",
        url: ajaxUrl + "/mobile/index/headData",
        async: false,
        data: {},
        success: function (data) {
            var result = data.result;
            var pc = result.pc;
           // console.log(pc);
            var catstr = ' <div class="nav-item nav-hook">' +
                '<span class="text">今日特卖</span>' +
                '</div>'
            for (var i = 0; i < pc.length; i++) {
                catstr += ' <div onclick="toChild(' + pc[i].catId + ')" class="nav-item nav-hook">' +
                    '<span class="text">' + pc[i].name + '</span>' +
                    '</div>'
            }
            console.log(catstr);
            $('#catList').html(catstr);
            var lunbo = "";
            var banners = result.banners;
            for (var i = 0; i < banners.length; i++) {
                lunbo = '<li class="swiper-slide">' +
                    '<a href="javascript:;"><img src="' + banners[i].image + '" alt=""></a></li>'
            }
            $('#lunbo').html(lunbo);
            $("#qianggou").attr("src", result.qgtu);


            var pl = ''
            var limitCountProducts = result.limitCountProducts;
            for (var j = 0; j < limitCountProducts.length && j < 6; j++) {
                pl += ' <div class="list-item" >' +
                     '<a href="details.html?id='+limitCountProducts[j].productId+'"    >'+
                    '        <img onclick="proDetail('+limitCountProducts[j].productId+')"  src="' + limitCountProducts[j].image + '" class="img" alt="">' +
                    '        <div class="name">' + limitCountProducts[j].productName + '</div>' +
                    '</a>'+
                    '        <div class="bottom">' +
                    '            <div class="price">￥' + limitCountProducts[j].price + '</div>' +
                    '            <div onclick="addCart('+limitCountProducts[j].productId+')" class="add-cart"></div>' +
                    '        </div>' +
                    '    </div>';
            }
            $('#list').html(pl);

            // $('#catProList').html(pl);

            var catString = "";
            for (var g = 0; g < pc.length; g++) {
                if (pc[g].products != null&&pc[g].products.length>0) {
                    catString += '<a  onclick="toCat('+pc[g].catId +')"><img  src="' + "http://mobile.zjpxny.com/file/" + pc[g].img + '" alt="" class="adve"></a>'

                    var products = pc[g].products;
                    var ps="";
                    for (var p = 0; p < products.length && p < 6; p++) {
                        //console.log(products[p]);
                        ps +=
                         ' <div  class="list-item">' +
                            '<a href="details.html?id='+products[p].id+'">'+
                            '        <img onclick="proDetail('+products[p].id+')" src="' + "http://mobile.zjpxny.com/file/" + products[p].image + '" class="img" alt="">' +
                            '        <div class="name">' + products[p].productName + '</div>' +
                            '</a>'+
                            '        <div class="bottom">' +
                            '            <div class="price">￥' + products[p].salePriceView + '</div>' +
                            '            <div onclick="addCart('+ products[p].id+')" class="add-cart"></div>' +
                            '        </div>' +
                            '    </div>';
                    }

                    catString+=ps

                }
                // pl += ' <div class="list-item">' +
                //     '        <img src="' + limitCountProducts[j].image + '" class="img" alt="">' +
                //     '        <div class="name">' + limitCountProducts[j].productName + '</div>' +
                //     '        <div class="bottom">' +
                //     '            <div class="price">￥' + limitCountProducts[j].price + '</div>' +
                //     '            <div class="add-cart"></div>' +
                //     '        </div>' +
                //     '    </div>';
            }

            $('#catProList').html(catString);

        }
    });

}


function toCat(id) {
     $.ajax({

        type: "post",
        url: ajaxUrl + "/mobile/product/category/getChildrenCategory",
        async: true,
        data: {'catId': id},
        success: function (data) {
            var result = data.result;
            console.log(result);

              window.location.href = 'more.html?catId='+id+'&pcatId='+result[0].id;
        }
    });
}

function addCart(productId) {
   $.ajax({
            type: "post",
            url: ajaxUrl + '/mobile/carItem/addProduct',
            async: true,
            //productId=412&memberId=623&normalId=508&num=1
            data: {'memberId': memberId, 'productId': productId, 'normalId': null, 'num': 1},
            success: function (data) {
                if (data.code == 0) {
                    alertMsg('成功加入购物车');
                } else {
                    alertMsg(data.message);
                }
                $('.spec-section').removeClass('on');
                $('.mask').hide();
                cartNum();
            },
            error: function () {
                errorTip();
            },
            complete: function () {

            }
        });
}
function proDetail(id) {
    window.location.href = 'details.html?id=' + id;
}
function toChild(cid) {
    console.log(cid);
    window.location.href = 'index2.html?catId=' + cid;
}